package com.huaxin.hxcloud.fragment;

import android.content.Context;
import android.content.res.Resources;
import android.view.View;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.huaxin.common.Entity.HxPunchCardViewBean;
import com.huaxin.common.utils.HxUtils;
import com.huaxin.hxcloud.R;

/**
 * @author songxf
 * @date 2017/11/30
 * @Desc 考勤打卡Adapter
 * Copyright HUAXIN DATA. All rights reserved.
 */
public class HxPunchCardAdapter extends BaseQuickAdapter<HxPunchCardViewBean.DataBean.SignBean, BaseViewHolder> {
    private final Resources mResources;
    private       String    mSelectDay;

    public HxPunchCardAdapter(Context context) {
        super(R.layout.item_runch_card);
        mResources = context.getResources();
    }

    /**
     * 选择日期的时间
     *
     * @param day
     */
    public void setSelectDay(String day) {
        this.mSelectDay = day;
    }

    @Override
    protected void convert(BaseViewHolder helper, HxPunchCardViewBean.DataBean.SignBean item) {
        TextView punchCardTypeTv = helper.getView(R.id.punch_card_type_tv);
        TextView punchCardAddressTv = helper.getView(R.id.punch_card_address_tv);
        TextView punchCardStateTv = helper.getView(R.id.punch_card_state_tv);
        TextView punchTimeTv = helper.getView(R.id.update_time_tv);
        helper.addOnClickListener(R.id.update_time_tv);
        String flagStr;
        String toTimes = HxUtils.getPatternToTimes(String.valueOf(item.getTime()));

        switch (helper.getAdapterPosition()) {
            case 0:
                flagStr = "上班打卡";
                punchCardTypeTv.setText((flagStr + toTimes));
                punchTimeTv.setVisibility(View.GONE);
                break;
            case 1:
                flagStr = "下班打卡";
                punchCardTypeTv.setText((flagStr + toTimes));
                if (HxUtils.getYearMonthDay().equals(mSelectDay)) {
                    punchTimeTv.setVisibility(View.VISIBLE);
                } else {
                    punchTimeTv.setVisibility(View.GONE);
                }
                break;
            default:
                break;
        }
        punchCardAddressTv.setText(item.getAddress());
        punchCardStateTv.setVisibility(View.GONE);
        // 签到类型：0.迟到、外勤；1.迟到、非外勤；2.准时、外勤；3.准时、非外勤
     /*   switch (item.getType()) {
            case 0:
            case 1:
                punchCardStateTv.setText("迟到");
                punchCardStateTv.setTextColor(mResources.getColor(R.color.red));
                punchCardStateTv.setBackground(mResources.getDrawable(R.drawable.bg_punch_card_state_red_shape));
                break;
            case 2:
            case 3:
                punchCardStateTv.setText("正常");
                punchCardStateTv.setTextColor(mResources.getColor(R.color.color_00A0E9));
                punchCardStateTv.setBackground(mResources.getDrawable(R.drawable.bg_punch_card_state_blue_shape));
                break;
            default:
                break;
        }*/


    }
}
